<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="root"></div>

  <script src="./js/react.development.js"></script>
  <script src="./js/react-dom.development.js"></script>
  <script src="./js/babel.min.js"></script>
  <script type="text/babel">
    const courses = [
      {id: 1, name: 'React'},
      {id: 3, name: 'Vue'},
      {id: 5, name: '小程序'},
      {id: 6, name: 'xxx'},
    ]

    // 1. 创建虚拟DOM

    /* 
    Warning: Each child in a list should have a unique "key" prop.
    数组中的虚拟DOM需要有唯一的key属性
    可以将key指定为下标或者id值 => 推荐使用id  为什么呢?(后面说)
    */

    // 根据数据的数组生成标签的数组  => 使用数组的什么方法?
    const lis = courses.map(c => <li key={c.id}>{c.name}</li>)

    const vNode = (
      <div>
        <h2>前端JS框架列表</h2>  
        <ul>
         {
            lis
            /* 
            [
              <li key={courses[0].id}>{courses[0].name}</li>,
              <li key={courses[1].id}>{courses[1].name}</li>, 
              <li key={courses[2].id}>{courses[2].name}</li>,
              <li key={courses[3].id}>{courses[3].name}</li>
            ] 
            */
         }
        </ul>
      </div>
    )

    // 2. 渲染虚拟DOM
    ReactDOM.render(vNode, document.getElementById('root'))
  </script>
</body>
</html>